package com.gitee.melin.bee.core.jdbc.dialect.dm;

import com.gitee.melin.bee.core.jdbc.dialect.DefaultTypeConvertor;
import com.gitee.melin.bee.core.jdbc.relational.ConnectionInfo;
import com.gitee.melin.bee.core.jdbc.enums.DataSourceType;
import com.gitee.melin.bee.core.jdbc.dialect.DataTypeConvertor;
import com.gitee.melin.bee.core.jdbc.dialect.AbstractJdbcDialect;
import com.gitee.melin.bee.core.jdbc.dialect.IDBQuery;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;

public class DaMengJdbcDialect extends AbstractJdbcDialect {

    @Override
    public DataSourceType getDataSourceType() {
        return DataSourceType.DAMENG;
    }

    public DaMengJdbcDialect(ConnectionInfo connectionInfo) {
        super(connectionInfo);
    }

    public DaMengJdbcDialect(Connection connection) {
        super(connection);
    }

    @Override
    protected IDBQuery getDBQuery() {
        return new DaMengQuery();
    }

    @Override
    protected DataTypeConvertor getTypeConvert() {
        return new DefaultTypeConvertor();
    }

    @Override
    protected Driver getDriver() throws SQLException {
        return loadDriver(DataSourceType.DAMENG.getDriverClass());
    }

    @Override
    protected boolean filterSchema(String schemaName) {
        if (schemaName.equalsIgnoreCase("sys")
                || schemaName.equalsIgnoreCase("sysauditor")
                || schemaName.equalsIgnoreCase("sysdba")
                || schemaName.equalsIgnoreCase("syssso")) {
            return false;
        }
        return super.filterSchema(schemaName);
    }

    @Override
    protected String getDDLColumnName() {
        return "ct_script";
    }

    @Override
    protected String createTableSql(String schemaName, String tableName) {
        return "SELECT DBMS_METADATA.GET_DDL('TABLE', '" + schemaName + "', '" + tableName + "') as ct_script FROM DUAL";
    }
}
